#client.py
#coding=utf-8  

import zmq
import cv2
import numpy as np

def subscribe_image():
    
    context = zmq.Context()
    subscriber =  context.socket(zmq.SUB)
    addr = 'ipc:///tmp/tmp_zmq.ipc'
    subscriber.connect(addr)
    subscriber.setsockopt(zmq.SUBSCRIBE, b"")
    print('connect to image publisher')

    while True:
        message = subscriber.recv()
        width = int.from_bytes(message[0:4], byteorder='little') 
        height = int.from_bytes(message[4:8], byteorder='little')
        channel = int.from_bytes(message[8:12], byteorder='little')
        message = message[12:]
        img = np.asarray(bytearray(message), dtype="uint8").reshape(height, width, channel)
        cv2.imshow('img', img)
        cv2.waitKey(1)